<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <father-page></father-page>
  </div>
  <script src="./vue.global.js"></script>
  <script src="https://unpkg.com/mitt/dist/mitt.umd.js"></script>
  <script>
   const emitter = mitt()
    const ChildPage1 = {
      template: `
        <div>
          <h3>子组件1</h3>  
          <button @click="emit">发送给兄弟</button>
        </div>
      `,
      data(){
        return {
          msg: '子组件1数据'
        }
      },
      methods: {
        emit() {
          emitter.emit('biubiu', this.msg);
        }
      }
    }
    const ChildPage2 = {
      template: `
        <div>
          <h3>子组件2</h3>  
          {{msg}}
        </div>
      `,
      data(){
        return {
          msg: ''
        }
      },
      mounted () {
        emitter.on('biubiu', (msg) => {
          this.msg = msg;
        })
      }
    }
    // 创建父组件
    const FatherPage = {
      template: `
        <div>
          <h2>父组件</h2>  
          <child-page1></child-page1>
          <hr/>
          <child-page2></child-page2>
        </div>
      `,
      components: {
        ChildPage1,
        ChildPage2
      }
    }
    
    const { createApp } = Vue;
    const app = createApp();
    app.component('FatherPage', FatherPage)
    app.mount('#app')
  </script>
</body>
</html>